package video.background.Utils;

import io.swagger.annotations.ApiOperation;
import video.background.Model.Users;


public class Verify {
    @ApiOperation("检查验证码是否正确")
    static public Result VerifyCheck(Users users,String verifyCode){
        String myVerifyCode = users.getVerifyCode();  //数据库中的验证码
        //验证用户id是否存在
        Long userId = users.getUserId();
        if (userId == null) return Result.Error("用户信息未找到",null);
        //验证验证码是否正确
        if(verifyCode.equals("")) return Result.Error("数据不全",null);
        if(myVerifyCode.equals("")) return Result.Error("请先发送验证码", null);
        if (!verifyCode.equals(myVerifyCode))
            return Result.Error("验证码错误",null);

        String verifyCodeTime = users.getVerifyCodeTime();  //验证码发送时间
        long timeBetween = DateTimeUtils.getTimeBetween(verifyCodeTime);
        if(timeBetween > 300) return Result.Error("验证码失效",null);
//        if(timeBetween < 60) return Result.Error("您的请求过于频繁，请稍后再试！",null);
        return Result.Success("验证码正确有效",null);
    }
}
